package com.fulihui.wgj.admin.integration.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fulihui.common.builder.web.PageViewBuilder;
import com.fulihui.common.conv.BeanConv;
import com.fulihui.common.result.web.PageView;
import com.fulihui.common.util.RpcResultCheckUtil;
import com.fulihui.wgj.admin.api.subscribeuser.request.SubscribeUserReq;
import com.fulihui.wgj.admin.api.subscribeuser.vo.SubscribeUserVO;
import com.fulihui.wgj.admin.integration.SubscribeUserClient;
import com.fulihui.wgj.facade.request.statistics.WxSubscribeStatisticsPageRequest;
import com.fulihui.wgj.facade.result.statistics.WxSubscribeStatisticsPageResult;
import com.fulihui.wgj.facade.service.statistics.WxSubscribeStatisticsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: JY
 * @date: 2018/7/5 13:42
 */
@Service("subscribeUserClient")
public class SubscribeUserClientImpl implements SubscribeUserClient {

    @Reference(version = "1.0.0")
    WxSubscribeStatisticsService wxSubscribeStatisticsService;

    @Override
    public PageView<SubscribeUserVO> list(SubscribeUserReq userReq) {

        WxSubscribeStatisticsPageRequest request = BeanConv.copy(userReq, WxSubscribeStatisticsPageRequest.class);
        WxSubscribeStatisticsPageResult pageResult = wxSubscribeStatisticsService.queryPageWxStatistics(request);

        List<SubscribeUserVO> subscribeUserVOS = null;
        if (RpcResultCheckUtil.isSuccess(pageResult)) {
            subscribeUserVOS = BeanConv.copy(pageResult.getValue(), SubscribeUserVO.class);
        }
        return PageViewBuilder.build(subscribeUserVOS, pageResult.getPage(),
                pageResult.getRows(), pageResult.getTotalRows());
    }

}
